package com.wj.algorithm.redmoney.one;

import java.util.Random;

/**
 * @author Smile.Wu
 * @date 2016年2月17日  上午11:57:37
 */
public class RandomMoneyUtil {

	public static double random(RandomMoney money) {
		int size = money.remainSize();
		if(size < 1) {
			return -1;
		}
		
		if(size == 1) {
			double out = (double)Math.round(money.remainMoney() * 100) / 100D;
			money.clear();
			return out;
		}
		
		double min = 0.01, max = 0;
		
		max = money.remainMoney() / size * 2;
		
		double m = max * new Random().nextDouble();
		
		m = m <= min ? min : m;
		
		money.decrease();
		
		return money.outMoney(Math.floor(m * 100) / 100D);
	}
}
